package com.youseu.taoliving.commodity.web;

import com.youseu.taoliving.commodity.entity.CategoryEntity;
import com.youseu.taoliving.commodity.service.CategoryService;
import com.youseu.taoliving.commodity.vo.Catalog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Tao
 * @version 1.0
 */
@Controller
public class IndexController {
    @Resource
    private CategoryService categoryService;

    @GetMapping(value = {"/","/index.html"})
    private String indexPage(Model model){
        List<CategoryEntity> list = categoryService.getFirstLevelCategories();
        model.addAttribute("categories",list);
        return "index";
    }

    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String,List<Catalog2Vo>> getCatalogJson(){
        return categoryService.getCatalogJson();
    }


}
